package com.breakfast.fun.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * 时间日期管理器
 * Created by Administrator on 2016/8/12.
 */
public class TimeUtil {

    //将数字转换为中文
    public static String changeEngToChi(int position) {
        switch (position) {
            case 0:
                return "【周一】";
            case 1:
                return "【周二】";
            case 2:
                return "【周三】";
            case 3:
                return "【周四】";
            case 4:
                return "【周五】";
            default:
                return null;
        }
    }

    /**
     * 通过时间计算周几
     *
     * @param date
     * @return
     */
    public static String CalcuDate(String date) {
        if (date == null) {
            return "";
        }
        String[] weeks = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");

        Calendar cal = Calendar.getInstance();
        try {
            cal.setTime(df.parse(date));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        int week_index = cal.get(Calendar.DAY_OF_WEEK) - 1;
        if (week_index < 0) {
            week_index = 0;
        }
        return weeks[week_index];
    }


}
